<template>
	<view class="content">
		<nav-bar title="用户信息" />
		<view class="add-con">
			<view class="margin">
				<view class="cu-card">
					<view class="card-title">基础信息</view>
					<u--form class="forminfo" labelPosition="left" :model="formData" labelWidth="auto">
						<u-form-item label="学号:" borderBottom>
							<u--input v-model="formData.xuehao" border="none" placeholder="请输入学号"
								inputAlign="right" />
						</u-form-item>
						<u-form-item label="姓名:" borderBottom>
							<u--input v-model="formData.xingming" border="none" placeholder="请输入姓名"
								inputAlign="right" />
						</u-form-item>
						<u-form-item label="性别:" borderBottom>
							<view class="flex justify-end" style="width: 100%;">
								<view>
									<u-radio-group v-model="formData.xingbie">
										<u-radio :name="true" label="男" :customStyle="{marginRight: '8px'}" />
										<u-radio :name="false" label="女" :customStyle="{marginRight: '8px'}" />
									</u-radio-group>
								</view>

							</view>
						</u-form-item>

						<u-form-item label="手机号:" borderBottom>
							<u--input v-model="formData.dianhua" border="none" placeholder="请输入手机号" inputAlign="right" />
						</u-form-item>
						<u-form-item label="院系:" borderBottom>
							<u--input v-model="formData.yuanxi" border="none" placeholder="请输入院系"
								inputAlign="right" />
						</u-form-item>
						<u-form-item label="班级:" borderBottom>
							<u--input v-model="formData.banji" border="none" placeholder="请输入班级"
								inputAlign="right" />
						</u-form-item>
						<view class="padding-top">照片：</view>
						<u-form-item label=" ">
							<upload-file v-model="formData.zhaopian"/>
						</u-form-item>
						<view class="padding-top">备注：</view>
						<u-form-item label=" ">
							<u--textarea v-model="formData.beizhu" placeholder="请输入内容" />
						</u-form-item>

					</u--form>
				</view>
				<view class="padding-tb flex align-center">
					<u-button type="primary" text="保存" @click="formSubmit"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		submitMinxins,
		detailMinxins
	} from '@/common/mixins/mixins.js'
	import uploadFile from '@/components/uploadFile.vue'
	export default {
		name: 'OwnerAdd',
		desc: '用户增加,详情，编辑',
		mixins: [submitMinxins, detailMinxins],
		components: {uploadFile},
		data() {
			return {
				userInfo: this.$store.state.vuex_user, //用户信息
				formData: {
					xingbie:true
				},
				rule: [{
					name: "xuehao",
					checkType: "notnull",
					errorMsg: "请输入学号"
				},{
					name: "xingming",
					checkType: "notnull",
					errorMsg: "请输入姓名"
				},{
					name: "dianhua",
					checkType: "phoneno",
					errorMsg: "请输入正确手机号"
				}, ],
				isAdd: true, //用于判断接口是否是增加
				urlapi: {
					add: '/xuesheng', //增加接口地址
					edit: '/xuesheng', //编辑接口
					del: '/xuesheng', //编辑接口
					detail: '/xuesheng', //编辑接口
				}
			}
		},
		onLoad() {
			this.initDatas(this.userInfo.id)
		},
		methods: {
			initDatas(id) {
				const that = this
				//存在参数 id ，可编辑 否则是增加
				if (id) {
					that.getDetailData(id).then(res => {
						that.formData = {
							...res,
						}
						if(!res.xingbie){
							that.formData.xingbie = true
						}
					}) //获取详情
				
					that.isAdd = false
				} else {
					that.isAdd = true
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>